//点击注册按钮
document.querySelector('#btn-register').addEventListener('click', async function () {
    //1.获取表单文本数据
    let username = document.querySelector('[name="username"]').value
    let password = document.querySelector('[name="password"]').value
    //2.表单校验:非空判断,正则校验
    if (username.length < 2 || username.length > 30) {
        return Toast.fail('账号长度应为:2-30个字符')
    } else if (password.length < 6 || password.length > 30) {
        return Toast.fail('密码长度应为:6-30个字符')
    }
    //3.ajax发送数据
    const { data } = await axios.post('/register', { username, password })
    console.log(data)
    //4.请求成功,跳转登录页
    Toast.success('注册成功')
    location.href = './login.html'
})